﻿using System;
using System.Linq;
using StreetPacMan.Server.Facade;

namespace StreetPacMan.Server.Rules.PlayerLocationChangeRules
{
    public class UpdateEntityDataRule : IHandlePlayerLocationChangedRule
    {
        public void Handle(PacManDataContext dataContext, ServerPollParameters serverPollParameters, ref bool shouldContinueHandling)
        {
            var updateEntity = dataContext.Players.Where(x => x.Id == serverPollParameters.EntityId).Single();
            updateEntity.StateEnum = serverPollParameters.IsEnabled ? PlayerState.JoinedActivePlaying : PlayerState.JoinedDisabled;
            updateEntity.LastCommunicationAt = DateTime.Now;
        }
    }
}